//https://blog.csdn.net/zl1zl2zl3/article/details/81357146
import { PureComponent } from 'react';
import {
    Row,
    Col,
    Form,
    Input,
    Select,
    Modal,
} from 'antd';

const FormItem = Form.Item;
const { Option } = Select;



// 修改表单
@Form.create()
class UpdateForm extends PureComponent {
    static defaultProps = {
        handleUpdateByDict: () => {},
    handleUpdateModalVisibleByDict: () => {},
values: {},
};

constructor(props) {
    super(props);
    this.state = {
        formVals: {
            id: props.values.id,
            dictid: props.values.dictid,
            title: props.values.title,
            dictvalue: props.values.dictvalue,
            key: props.values.key,
        },
    };

}

 handleLocalUpdate = () => {
    const { form, handleUpdateByDict } = this.props;
    const { formVals: oldValue } = this.state;
    form.validateFields((err, fieldsValue) => {
      if (err) return;
      const formVals = { ...oldValue, ...fieldsValue };
      this.setState(
        {
          formVals,
        }
      );
     
     handleUpdateByDict(formVals);

    });
};


renderContent = (formVals) => {
    const { form } = this.props;

    return (
        <Form  layout="vertical">

            <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

                <Col  md={24} sm={48}>
                    <FormItem  label="常量显示名称">
                        {form.getFieldDecorator('title', {
                        rules: [{ required: true, message: '请输入常亮显示名称！', min: 1 }],
                        initialValue: formVals.title,
                        })(<Input placeholder="请输入" />)}
                    </FormItem>
                </Col>

          	</Row>

    	</Form>
	);

};



render() {
    const { updateModalVisibleByDict, handleUpdateModalVisibleByDict, values} = this.props;
    const {  formVals } = this.state;

    return (
	        <Modal
	    width={800}
	    bodyStyle={{ padding: '32px 40px 48px' }}
	    destroyOnClose
	    title="修改"
	    visible={updateModalVisibleByDict}
	    onOk={() => this.handleLocalUpdate()}
	    onCancel={() => handleUpdateModalVisibleByDict(false, values)}
	    afterClose={() => handleUpdateModalVisibleByDict()}
		>
	
	    	{this.renderContent(formVals)}
		</Modal>
	);
}

}

export default UpdateForm;

